//
//  AccountNumCell.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/15.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "AccountNumCell.h"
#import "CommonMacro.h"

@implementation AccountNumCell

- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self initWithSubviews];
    }
    return self;
}

- (void)initWithSubviews
{
    CGFloat buttonX = SCREEN_WIDTH*0.54;
    CGFloat buttonY = 18;
    CGFloat buttonW = SCREEN_WIDTH*0.08;
    CGFloat buttonH = 24;
    CGFloat Marggin = 8;
    
    //1.减
    self.reductionButton = [[UIButton alloc] initWithFrame:CGRectMake(buttonX, buttonY, buttonW, buttonH)];
    self.reductionButton.layer.borderWidth = 1;
    self.reductionButton.layer.borderColor = UIColorWithRGBA(230, 230, 230, 1).CGColor;
    [self.reductionButton setTitle:@"-" forState:UIControlStateNormal];
    [self.reductionButton setTitleColor:UIColorWithRGBA(166, 166, 166, 1) forState:UIControlStateNormal];
    [self addSubview:self.reductionButton];
    self.reductionButton.tag = 1000;
    [self.reductionButton addTarget:self action:@selector(finishAddAndReduction:) forControlEvents:UIControlEventTouchUpInside];
    
    //2.购买数量
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(3, 20,SCREEN_WIDTH*0.4 ,buttonH)];
    self.titleLabel.text = @"购买数量：";
    self.titleLabel.font = [UIFont fontWithName:nil size:18];
     self.titleLabel.textColor = UIColorWithRGBA(168, 168, 168, 1);
    [self addSubview:self.titleLabel];
    
    //3.货物数量
    self.totalNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.reductionButton.frame.size.width+self.reductionButton.frame.origin.x+Marggin,buttonY-4, buttonW*1.7, buttonH*1.5)];
    self.totalNumLabel.textColor = UIColorWithRGBA(166, 166, 166, 1);
    self.totalNumLabel.layer.borderWidth = 1;
    self.totalNumLabel.layer.borderColor = UIColorWithRGBA(230, 230, 230, 1).CGColor;
    
    self.totalNumLabel.textColor = UIColorWithRGBA(168, 168, 168, 1);
    [self addSubview:self.totalNumLabel];
    
    //4.加
    self.addButton = [[UIButton alloc] initWithFrame:CGRectMake(self.totalNumLabel.frame.size.width+self.totalNumLabel.frame.origin.x+Marggin, buttonY, buttonW, buttonH)];
    self.addButton.layer.borderWidth = 1;
    [self.addButton setTitleColor:UIColorWithRGBA(166, 166, 166, 1) forState:UIControlStateNormal];
    self.addButton.layer.borderColor = UIColorWithRGBA(230, 230, 230, 1).CGColor;
    [self.addButton setTitle:@"+" forState:UIControlStateNormal];
     [self.addButton setTitleColor:UIColorWithRGBA(168, 168, 168, 1) forState:UIControlStateNormal];
    [self addSubview:self.addButton];
    self.addButton.tag = 1001;
    [self.addButton addTarget:self action:@selector(finishAddAndReduction:) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark 执行加减计算
- (void)finishAddAndReduction:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(helpAddAndReduction:)]) {
        [self.delegate helpAddAndReduction:button];
    }
}
@end
